<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <f:loadBundle  basename="com.Bundle" var="msg"/>
    <h:body>
        <f:view>
            <h:form prependId="false" id="form1">
                <h:outputScript name="ajax.js" library="javax.faces" target="head"/>
                <h1><h:outputText value="#{msg.purchase_header}"/></h1>
                <h:panelGrid columns="2">

                    <h:outputLabel value="#{msg.purchase_vendor}" for="vendor" />
                    <h:selectOneMenu id="vendor" value="#{purchaseBean.purchaseDetails.vendor}" title="Vendor" >
                        <f:selectItems value="#{purchaseBean.vendors}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="#{msg.purchase_item}" for="item" />
                    <h:selectOneMenu id="item" value="#{purchaseBean.lineItem.item}" title="Items" >
                        <f:selectItems value="#{purchaseBean.items}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="#{msg.purchase_quantity}" for="quantity" />
                    <h:inputText id="quantity" value="#{purchaseBean.lineItem.quantity}" title="Quantity" />

                    <br/>
                    <h:commandButton id="addItem"  value="#{msg.add_button}" actionListener="#{purchaseBean.addItem}">
                        <!--<f:ajax render=":form1:out"/>-->
                    </h:commandButton>
                    <br/>
                    <h:panelGroup id="out">
                        <h:dataTable  value="#{purchaseBean.lineItems}"  var="pItem" rendered="#{!empty purchaseBean.lineItems}"
                                      rowClasses="firstRow,secondRow"
                                      headerClass="tableHeader"
                                      style="border-collapse:collapse;vertical-align:middle; text-decoration:none;margin-left:15px;">                            >
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msg.supplier_datatable_address}"/>
                                </f:facet>
                                <h:outputText value="#{pItem.item.name}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msg.purchase_quantity}"/>
                                </f:facet>
                                <h:outputText value="#{pItem.quantity}"/>
                            </h:column>
                        </h:dataTable>
                    </h:panelGroup>
                </h:panelGrid>
                <h:commandButton value="#{msg.save_button}" action="#{purchaseBean.processRequest}"/>
            </h:form>
        </f:view>
    </h:body>
</html>